<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
    FB.init({appId: '<%=Misc.find(2).detail%>', status: true, cookie: true, xfbml: true});
    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        // the user is logged in and has authenticated your
        // app, and response.authResponse supplies
        // the user's ID, a valid access token, a signed
        // request, and the time the access token
        // and signed request each expire
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        document.getElementById('fbuser').innerHTML = uid;
        document.getElementById('uid').value = uid;
        document.getElementById('profilepic').innerHTML = '<img src="http://graph.facebook.com/'+uid+'/picture"/>';
        document.getElementById('fbbt').innerHTML = "<input type='submit' value='Process to Game'/>";
      } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook,
        // but has not authenticated your app
        document.getElementById('fbuser').innerHTML = "คุณยังไม่ได้อนุญาตการเชื่อมต่อกับ Facebook"
      } else {
        document.getElementById('fbuser').innerHTML = "คุณยังไม่ได้ login เข้าสู่ Facebook"
      }
    });
    FB.Event.subscribe('auth.login', function(response) {
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        document.getElementById('fbuser').innerHTML = uid;
        document.getElementById('uid').value = uid;
        document.getElementById('profilepic').innerHTML = '<img src="http://graph.facebook.com/'+uid+'/picture"/>';
        document.getElementById('fbbt').innerHTML = "<input type='submit' value='Process to Game'/>";
    });
</script>